package ycl.important.common.utils;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import ycl.important.common.models.base.BaseQuery;
import ycl.important.common.models.base.PageParams;

/**
 * 分页工具
 *
 * @author: YCL
 * @date: 2021-08-31 21:05:27
 */
public class PageUtil {


	/**
	 * 获取分页
	 *
	 * @param query 分页查询数据
	 * @param t 分页的泛型类
	 * @param <T> 任意类
	 * @return 分页
	 */
	public static <T> Page<T> getPage(BaseQuery query, Class<T> t) {
		PageParams params = getParams(query);
		return new Page<>(params.getCurrent(), params.getSize());
	}


	private static PageParams getParams(BaseQuery query) {
		int current = query.getCurrent();
		int size = query.getSize();

		if (current < 1) current = 1;
		if (size < 1) size = 10;
		return new PageParams(current, size);
	}
}
